package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceGrn;
import com.zjjk.transfer.source.mapper.SourceGrnMapper;
import com.zjjk.transfer.source.service.SourceGrnService;
import com.zjjk.transfer.source.param.SourceGrnPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 出入库单表 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceGrnServiceImpl extends BaseServiceImpl<SourceGrnMapper, SourceGrn> implements SourceGrnService {

    @Autowired
    private SourceGrnMapper sourceGrnMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceGrn(SourceGrn sourceGrn) throws Exception {
        return super.save(sourceGrn);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceGrn(SourceGrn sourceGrn) throws Exception {
        return super.updateById(sourceGrn);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceGrn(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceGrn> getSourceGrnPageList(SourceGrnPageParam sourceGrnPageParam) throws Exception {
        Page<SourceGrn> page = new PageInfo<>(sourceGrnPageParam, OrderItem.desc(getLambdaColumn(SourceGrn::getCreateTime)));
        LambdaQueryWrapper<SourceGrn> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceGrn> iPage = sourceGrnMapper.selectPage(page, wrapper);
        return new Paging<SourceGrn>(iPage);
    }

}
